﻿<?php
include "../lib/DAL/DmNganh.php";
class DmNganhBLL{
    function __construct(){
        
    }
    
    function __destruct(){
        
    }
    
    function setNganhBLL($row){
        $nganh= new DmNganhDAL();
        $nganh->setdmNganh($row['madm_nganh'],$row['ten_nganh'],$row['ten_vt_nganh'],$row['gioithieu_nganh']);
        return $nganh;
         
    }
    
    public function getNganh($madm_nganh){
        $sql = "select * from dm_nganh where madm_nganh ='".$madm_nganh."'";        
        $row = mysql_fetch_array(mysql_query($sql));
       return $this->setNganhBLL($row);
        
    }
    public function InsertNganh($nganh)
    {
        $sql="  INSERT INTO dm_Nganh(madm_nganh,ten_nganh,ten_vt_nganh,gioithieu_nganh) 
                VALUES('".$nganh->getmadm_nganh()."','".$nganh->getten_nganh()."','".$nganh->getten_vt_nganh()."','".$nganh->getgioithieu_nganh()."')";
        
        $kq= mysql_query($sql);
        
        return $kq;
    }
   
    public function updateNganh($nganh){
        $sql="UPDATE dm_nganh
            SET
            ten_nganh = '".$nganh->getten_nganh()."' 
            ,ten_vt_nganh = '".$nganh->getten_vt_nganh()."'
            ,gioithieu_nganh = '".$nganh->getgioithieu_nganh()."'
            WHERE madm_nganh ='".$nganh->getmadm_nganh()."'";
          $result = mysql_query($sql) or die (mysql_error());
       return $result;
    }
    
    public function deleteNganh($madm_nganh){
        $sql="delete from dm_nganh where madm_nganh = '".$madm_nganh."'";
      //  $sql="select * from dm_he_daotao where ma_hdt = '".$ma_hdt."'";
         $result = mysql_query($sql) or die (mysql_error());
       return $result;
    }
    public function getListNganh(){
      $result = mysql_query("select * from dm_nganh");
      $arr_nganh = array();
      
      while($row = mysql_fetch_array($result)){
        $arr_nganh[] =  $this->setNganhBLL($row);
      }
      return $arr_nganh;
    }
    
    public function countNganh(){
        $songanh=mysql_query("select madm_nganh from dm_nganh");
        
        return mysql_num_rows($songanh); 
    }
    
    
    
}

?>